/*
 * Copyright 2012 Sedov Eduard.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.es.registry;

import java.util.List;
import java.util.Set;

/**
 *
 * @author Sedov Eduard
 */
public interface Registry {

    public static final String PATH_DELIMITER = "/";
    public static final String DOT = ".";
    public static final String DOUBLE_DOTS = "..";

    /**
     * Return {@code true} if a directory or a value associated with given name
     * exist.
     *
     * @param name the relative or absolute path
     * @return {@code true} if {@code name} exist
     */
    public boolean isExist(String name);

    /**
     * Returns {@code true} if the given name is a directory.
     *
     * @param name the relative or absolute path
     * @return {@code true} if {@code name} is a directory
     */
    public boolean isDirectory(String name);

    /**
     * Returns name of current directory.
     *
     * @return name current directory
     */
    public String cd();

    /**
     * Changes the current directory. Allowed values are:<br> '' or '.' keeps
     * the previous current directory<br> '..' changes to parent directory<br>
     * '/a/b/c' changes to directory 'abc', where 'a' is a child of root<br>
     * 'a/b/c' changes to directory 'abc', where 'a' is a child of current
     * directory<br>
     *
     * @param name the absolute or relative path
     * @return the new current path
     */
    public String cd(String name);

    /**
     * Makes directory path specified by name parameter. Allowed are absolute
     * and relative paths.
     *
     * @param name path to create
     */
    public void mkdir(String name);

    /**
     * Removes the directory specified by given name. Allowed are absolute and
     * relative paths.
     *
     * @param name directory to remove
     */
    public void rmdir(String name);

    /**
     * Returns the value associated with the given path.
     *
     * @param <T> the type of value
     * @param name the path
     * @return the value or {@code null} if no value set
     */
    public <T> T get(String path);

    /**
     * Inserts the given value and associates it with the given path.
     *
     * @param <T> the type of value
     * @param name the relative or absolute path
     * @param value the value. May not be an instance of {@link Node}.
     * @return the previous value or {@code null} if no such exist
     */
    public <T> T put(String path, T value);

    /**
     * Removes the value associated with the given path.
     *
     * @param <T> the type of value
     * @param name the relative or absolute path
     * @return the removed value or {@code null} if no such exist
     */
    public <T> T delete(String path);

    /**
     * Returns names of children (directories and values) of current directory.
     *
     * @return a set of names
     */
    public Set<String> list();

    /**
     * Renames a directory of value described by {@code oldName}.
     *
     * @param oldName the path to rename
     * @param newName a new name
     */
    public void rename(String oldName, String newName);

    /**
     * Puts the given listener to internal listener list.
     *
     * @param listener the listner to put
     */
    public void addListener(RegistryListener listener);

    /**
     * Removes the given listener from internal listener list.
     *
     * @param listener the listener to remove
     */
    public void removeListener(RegistryListener listener);

    /**
     * Returns all registered listeners.
     *
     * @return a list with all registered listeners
     */
    public List<RegistryListener> getListeners();
}
